﻿/* Define a class BitArray64 to hold 64 bit values inside an ulong value.
 * Implement IEnumerable<int> and Equals(…), GetHashCode(), [], == and !=. */

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _3.BitArray64
{
    class BitArray64 : IEnumerable<int>
    {
        private ulong bitArray;

        public BitArray64(ulong value)
        {
            this.bitArray = value;
        }

        public IEnumerator<int> GetEnumerator()
        {
            string bitArrayString = ULongToBinary(this.bitArray);
            for (int i = 0; i < bitArrayString.Length; i++)
            {
                yield return int.Parse(bitArrayString[i].ToString());
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        private string ULongToBinary(ulong number)
        {
            ulong remainder;
            string result = string.Empty;
            while (number > 0)
            {
                remainder = number % 2;
                number /= 2;
                result = remainder.ToString() + result;
            }
            return result;
        }
    }
}
